package com.example.mybatispuls.config;


import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Description Swagger文档
 * - @Configuration：声明配置文件
 * - @EnableSwagger2：开启Swagger2
 * - @EnableSwaggerBootstrapUI：开启SwaggerBootstrapUI
 * - basePackage：声明主包
 * - title:文档名称
 * - 团队访问网址：termsOfServiceUrl
 * - 账号信息：Contact
 * - version：版本
 * - 访问路径 http://127.0.0.1:9992/doc.html
 **/
@Configuration
@EnableSwagger2
@EnableSwaggerBootstrapUI
public class SwaggerConfiguration {

    @Value("${server.port}")
    private int serverPort;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //配置全局的controller 接口文档，一般开发中都是在同一个包下
                .apis(RequestHandlerSelectors.basePackage("com.example.mybatispuls"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口管理文档")
                .description("接口管理文档")
                .termsOfServiceUrl("http://127.0.0.1:" + serverPort)
                .contact(new Contact("文档接口", "", "381171236@qq.com"))
                .version("1.0")
                .build();
    }

}


